﻿using System.Windows;
using System.Windows.Controls;
using Oxage.CNC.Models;
using Oxage.Models;

namespace Oxage.Views
{
	public partial class TransformView : UserControl
	{
		#region Constructor
		public TransformView()
		{
			InitializeComponent();
			this.Focusable = true;
		}
		#endregion

		#region Public properties
		public TransformViewModel ViewModel
		{
			get
			{
				return this.DataContext as TransformViewModel;
			}
		}
		#endregion

		#region Event handlers
		private void Transform_Click(object sender, RoutedEventArgs e)
		{
			double factor = 1.0; //TODO: Read from input field
			string gcode = App.ViewModel.View.Editor.textEditor.Text;

			//Convert string to objects
			var serializer = new GCodeSerializer();
			var g1 = serializer.Deserialize(gcode);

			//Perform a transformation
			var transformer = new GCodeTransformer();
			var g2 = transformer.Scale(g1, new Vector3(factor, factor, factor));

			//Return output as string
			App.ViewModel.View.Editor.textEditor.Text = serializer.Serialize(g2);
		}
		#endregion
	}
}
